﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenUtil.Dto;
using GenUtil.Util;
using DataLayer.Dao;

namespace ServiceLayer.Service.Impl
{
    public class CustomerServiceImpl : CustomerService
    {
        Logger logger = new Logger(typeof(CustomerServiceImpl));
        public void InsertCustomerDto(CustomerDto customerDto)
        {
            logger.debug("Entering CustomerServiceImpl.InsertCustomerDto()");
            try
            {
                int maxCustomerNo = DaoFactory.getCustomerDao().getMaxCustomerNo();
                customerDto.CustomerNo = maxCustomerNo + 1;
                customerDto.LastUpdDt = DateTime.Now;
                customerDto.LastUpdUserId = "Shaibal";
                DaoFactory.getCustomerDao().InsertCustomerDto(customerDto);
            }
            catch (Exception e)
            {
                logger.fatal("Exception in CustomerServiceImpl.InsertCustomerDto():" + e.Message, e);
                throw new Exception("Exception in CustomerServiceImpl.InsertCustomerDto():" + e.Message, e);
            }
            logger.debug("Exiting CustomerServiceImpl.InsertCustomerDto()");
        }
        public CustomerDto GetCustomerDto(int CustomerNo)
        {
            logger.debug("Entering CustomerDaoSql.getCustomerDto()");
            CustomerDto customerDto = null;
            try
            {
                customerDto = DaoFactory.getCustomerDao().GetCustomerDto(CustomerNo);
            }
            catch (Exception e)
            {
                logger.fatal("Exception in CustomerServiceImpl.getCustomerDto():" + e.Message, e);
                throw new Exception("Exception in CustomerServiceImpl.getCustomerDto():" + e.Message, e);
            }
            logger.debug("Exiting CustomerServiceImpl.GetCustomerDto()");
            return customerDto;
        }
        public List<CustomerDto> getCustomerDtos()
        {
            logger.debug("Entering CustomerDaoSql.getCustomerDtos()");
            List<CustomerDto> customerDtos = null;
            try
            {
                customerDtos = DaoFactory.getCustomerDao().getCustomerDtos();
            }
            catch (Exception e)
            {
                logger.fatal("Exception in CustomerServiceImpl.getCustomerDtos():" + e.Message, e);
                throw new Exception("Exception in CustomerServiceImpl.getCustomerDtos():" + e.Message, e);
            }
            logger.debug("Exiting CustomerServiceImpl.getCustomerDtos()");
            return customerDtos;
        }
    }

}

